home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / crt.swg / 0017_CRT Clone.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-02  |  6.6 KB  |  224 lines

  1. {
  2.  Well here it is again, its a little rough and some of the Crt.tpu Functions
  3. are left out. This Unit will generate Ansi TextColor and TextBackGrounds.
  4. Becuase of the Ansi screen Writes you can send the Program to the com port
  5. just by using CTTY or GateWay in a bat File before you start your Program.
  6. }
  7.  
  8. Unit CrtClone;
  9.  
  10. Interface
  11.  
  12. Const
  13.   { Foreground and background color Constants }
  14.   Black         = 0;
  15.   Blue          = 1;
  16.   Green         = 2;
  17.   Cyan          = 3;
  18.   Red           = 4;
  19.   Magenta       = 5;
  20.   Brown         = 6;
  21.   LightGray     = 7;
  22.  
  23.   { Foreground color Constants }
  24.   DarkGray      = 8;
  25.   LightBlue     = 9;
  26.   LightGreen    = 10;
  27.   LightCyan     = 11;
  28.   LightRed      = 12;
  29.   LightMagenta  = 13;
  30.   Yellow        = 14;
  31.   White         = 15;
  32.  
  33.   { Add-in For blinking }
  34.   Blink         = 128;
  35.  
  36. Var
  37.   { Interface Variables }
  38.   CheckBreak : Boolean;    { Enable Ctrl-Break }
  39.   CheckEOF   : Boolean;    { Enable Ctrl-Z }
  40.  
  41. Procedure TextColor(Color : Byte);
  42. Procedure TextBackground(Color : Byte);
  43. Function  KeyPressed : Boolean;
  44. Function  GetKey : Char;
  45. Function  ReadKey : Char;
  46. Function  WhereX : Byte;
  47. Function  WhereY : Byte;
  48. Procedure NormVideo;
  49. Procedure ClrEol;
  50. Procedure ClrScr;
  51. Procedure GotoXY(X, Y : Byte);
  52.  
  53.  
  54. Implementation
  55.  
  56. Function KeyPressed : Boolean;
  57. { Replacement For Crt.KeyPressed }
  58. {  ;Detects whether a key is pressed}
  59. {  ;Does nothing With the key}
  60. {  ;Returns True if key is pressed}
  61. {  ;Otherwise, False}
  62. {  ;Key remains in kbd buffer}
  63. Var
  64.   IsThere : Byte;
  65. begin
  66.   Inline(
  67.     $B4/$0B/               {    MOV AH,+$0B         ;Get input status}
  68.     $CD/$21/               {    INT $21             ;Call Dos}
  69.     $88/$86/>ISTHERE);     {    MOV >IsThere[BP],AL ;Move into Variable}
  70.   KeyPressed := (IsThere = $FF);
  71. end;
  72.  
  73. Procedure  ClrEol;     { ANSI replacement For Crt.ClrEol }
  74. begin
  75.   Write(#27'[K');
  76. end;
  77.  
  78. Procedure ClrScr;     { ANSI replacement For Crt.ClrScr }
  79. begin
  80.   Write(#27'[2J');
  81. end;
  82.  
  83. Function GetKey : Char;     { Additional Function.  Not in Crt Unit }
  84. Var
  85.   CH : Char;
  86. begin
  87.   Inline(
  88.   {; Function GetKey : Char}
  89.   {; Clears the keyboard buffer then waits Until}
  90.   {; a key is struck.  if the key is a special, e.g.}
  91.   {; Function key, goes back and reads the next}
  92.   {; Byte in the keyboard buffer.  Thus does}
  93.   {; nothing special With Function keys.}
  94.      $B4/$0C        {       MOV  AH,$0C      ;Set up to clear buffer}
  95.      /$B0/$08       {       MOV  AL,8        ;then to get a Char}
  96.      /$CD/$21       {SPCL:  INT  $21         ;Call Dos}
  97.      /$3C/$00       {       CMP  AL,0        ;if it's a 0 Byte}
  98.      /$75/$04       {       JNZ  CHRDY       ;is spec., get second Byte}
  99.      /$B4/$08       {       MOV  AH,8        ;else set up For another}
  100.      /$EB/$F6       {       JMP  SHORT SPCL  ;and get it}
  101.      /$88/$46/>CH   {CHRDY: MOV  >CH[BP],AL  ;else put into Function return}
  102.    );
  103.   if CheckBreak and (Ch = #3) then
  104.   begin        {if CheckBreak is True and it's a ^C}
  105.     Inline(    {then execute Ctrl_Brk}
  106.     $CD/$23);
  107.   end;
  108.   GetKey := Ch;
  109. end; {Inline Function GetKey}
  110.  
  111.  
  112. Function ReadKey : Char;  { Replacement For Crt.ReadKey }
  113. Var
  114.   chrout : Char;
  115. begin
  116.   {  ;Just like ReadKey in Crt Unit}
  117.   Inline(
  118.   $B4/$07/               {  MOV AH,$07          ;Char input w/o echo}
  119.   $CD/$21/               {  INT $21             ;Call Dos}
  120.   $88/$86/>CHROUT);      {  MOV >chrout[bp],AL  ;Put into Variable}
  121.   if CheckBreak and (chrout = #3) then  {if it's a ^C and CheckBreak True}
  122.   {then execute Ctrl_Brk}
  123.     Inline($CD/$23);           {     INT $23}
  124.   ReadKey := chrout;                    {else return Character}
  125. end;
  126.  
  127. Function WhereX : Byte;       { ANSI replacement For Crt.WhereX }
  128. Var                         { Cursor position report. This is column or }
  129.   ch  : Char;               { X axis report.}
  130.   st  : String;
  131.   st1 : String[2];
  132.   x   : Byte;
  133.   i   : Integer;
  134. begin
  135.   Write(#27'[6n');          { Ansi String to get X-Y position }
  136.   st := '';                 { We will only use X here }
  137.   ch := #0;                 { Make sure Character is not 'R' }
  138.   While ch <> 'R' do        { Return will be }
  139.   begin                   { Esc - [ - Ypos - ; - Xpos - R }
  140.     ch := #0;
  141.     ch := ReadKey;        { Get one }
  142.     st := st + ch;        { Build String }
  143.   end;
  144.   St1 := copy(St,6,2);    { Pick off subString having number in ASCII}
  145.   Val(St1,x,i);           { Make it numeric }
  146.   WhereX := x;            { Return the number }
  147. end;
  148.  
  149. Function WhereY : Byte;       { ANSI replacement For Crt.WhereY }
  150. Var                         { Cursor position report.  This is row or }
  151.   ch  : Char;               { Y axis report.}
  152.   st  : String;
  153.   st1 : String[2];
  154.   y   : Byte;
  155.   i   : Integer;
  156. begin
  157.   Write(#27'[6n');          { Ansi String to get X-Y position }
  158.   st := '';                 { We will only use Y here }
  159.   ch := #0;                 { Make sure Character is not 'R' }
  160.   While ch <> 'R' do        { Return will be }
  161.   begin                   { Esc - [ - Ypos - ; - Xpos - R }
  162.     ch := #0;
  163.     ch := ReadKey;        { Get one }
  164.     st := st + ch;        { Build String }
  165.   end;
  166.   St1 := copy(St,3,2);    { Pick off subString having number in ASCII}
  167.   Val(St1,y,i);           { Make it numeric }
  168.   WhereY := y;            { Return the number }
  169. end;
  170.  
  171.  
  172. Procedure GotoXY(x : Byte ; y : Byte); { ANSI replacement For Crt.GoToXY}
  173. begin
  174.   if (x < 1) or (y < 1) then
  175.     Exit;
  176.   if (x > 80) or (y > 25) then
  177.     Exit;
  178.   Write(#27'[', y, ';', x, 'H');
  179. end;
  180.  
  181. Procedure TextBackGround(Color : Byte);
  182. begin
  183.  Case color of
  184.    0 : Write(#27#91#52#48#109);
  185.    1 : Write(#27#91#52#52#109);
  186.    2 : Write(#27#91#52#50#109);
  187.    3 : Write(#27#91#52#54#109);
  188.    4 : Write(#27#91#52#49#109);
  189.    5 : Write(#27#91#52#53#109);
  190.    6 : Write(#27#91#52#51#109);
  191.    6 : Write(#27#91#52#55#109);
  192.   end;
  193. end;
  194.  
  195. Procedure TextColor(Color : Byte);
  196.  begin
  197.   Case color of
  198.      0 : Write(#27#91#51#48#109);
  199.      1 : Write(#27#91#51#52#109);
  200.      2 : Write(#27#91#51#50#109);
  201.      3 : Write(#27#91#51#54#109);
  202.      4 : Write(#27#91#51#49#109);
  203.      5 : Write(#27#91#51#53#109);
  204.      6 : Write(#27#91#51#51#109);
  205.      7 : Write(#27#91#51#55#109);
  206.      8 : Write(#27#91#49#59#51#48#109);
  207.      9 : Write(#27#91#49#59#51#52#109);
  208.     10 : Write(#27#91#49#59#51#50#109);
  209.     11 : Write(#27#91#49#59#51#54#109);
  210.     12 : Write(#27#91#49#59#51#49#109);
  211.     13 : Write(#27#91#49#59#51#53#109);
  212.     14 : Write(#27#91#49#59#51#51#109);
  213.     15 : Write(#27#91#49#59#51#55#109);
  214.    128 : Write(#27#91#53#109);
  215.   end;
  216. end;
  217.  
  218. Procedure NormVideo;
  219. begin
  220.   Write(#27#91#48#109);
  221. end;
  222.  
  223. end.
  224.